const express = require('express');
//引入页面返回控制器
const pagesController = require('./controllers/pagesController.js');
const userController = require('./controllers/userController.js');
const postController=require('./controllers/postController.js');
const cateController=require('./controllers/cateController.js');
const uploadController=require('./controllers/uploadController.js');
const optionsController=require('./controllers/optionsController.js');
const router = express.Router();

//配置路由
//路由中间件的回调函数,不是我们自己调用,是服务器响应请求时调用
//调用时,会给这个回调函数传入两个参数  req  res
//后台页面
router.get('/admin/index', pagesController.getAdminIndexPage)
    .get('/admin/categories', pagesController.getAdminCategoriesPage)
    .get('/admin/login', pagesController.getAdminLoginPage)
    .get('/admin/comments', pagesController.getAdminCommentsPage)
    .get('/admin/nav-menus', pagesController.getAdminNavMenusPage)
    .get('/admin/password-reset', pagesController.getAdminPasswordResetPage)
    .get('/admin/post-add', pagesController.getAdminPostAddPage)
    .get('/admin/posts', pagesController.getAdminPostsPage)
    .get('/admin/profile', pagesController.getAdminProfilePage)
    .get('/admin/slides', pagesController.getAdminSlidesPage)
    .get('/admin/settings', pagesController.getAdminSettingsPage)
    .get('/admin/users', pagesController.getAdminUsersPage)
    //前台页面
    .get('/', pagesController.getIndexPage)
    .get('/detail', pagesController.getDetailPage)
    .get('/list', pagesController.getListPage)
    //业务处理路由
    .post('/login', userController.login)

    .get('/getAllPost', postController.getAllPost)
    .get('/getAllCate',cateController.getAllCate)
    .get('/getPostById',postController.getPostById)
    .post('/addPost',postController.addPost)
    .post('/editPostById',postController.editPostById)
    .get('/delPostById',postController.delPostById)
    .post('/editCate',cateController.editCate)
    .post('/addCate',cateController.addCate)
    .get('/delCateById',cateController.delCateById)
    .post('/addMenu',optionsController.addMenu)
    .get('/getSettings',optionsController.getSettings)
    .post('/updateSettings',optionsController.updateSettings)

    .post('/uploadFile',uploadController.uploadFile)//文件上传
//暴露
module.exports = router;